package com.ankicoo.practice.daily;

import java.util.*;

public class KillOdd {
    public static void main(String[] args) {
        Map<Integer, Integer> positionMap = new HashMap<>();
        Map<Integer, Integer> resultMap = new HashMap<>();

        int number = 600;
        int expTimes = 100000;
        for (int i = 0; i < number; i++) {
            positionMap.put(i, i+1);
            resultMap.put(i+1,0);
        }
        Random random = new Random();
        while ( expTimes > 0){
            List<Integer> numbers = new ArrayList<>();
            for (int i1 = 0; i1 < number; i1++) {
                numbers.add(i1+1);
            }

            while (numbers.size()>1){
//                int center = (numbers.size() + 1) / 2;
//                int position = random.nextInt(center) * 2;
                int position = random.nextInt(numbers.size()) ;
                numbers.remove(position);
            }
            int latest = numbers.get(0);
            resultMap.put(latest,resultMap.get(latest)+1);

            expTimes -- ;
        }
        for (Integer integer : resultMap.keySet()) {
            System.out.println("数字"+integer+"存活次数 : "+(resultMap.get(integer)));
        }
    }
}
